package com.shirley.thread;

public class ShirleyThread extends Thread {
    private String label;

    public ShirleyThread(String label) {
        this.label = label;
    }

    @Override
    public void run() {
        System.out.println(label + " is running...");
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(label + " is done.");

    }

    public static void main(String[] args) throws InterruptedException {
        ShirleyThread thread1 = new ShirleyThread("Task 1");
        ShirleyThread thread2 = new ShirleyThread("Task 2");
        thread1.start();
        thread2.start();

        while (thread1.isAlive() || thread2.isAlive()) {
            System.out.println(thread1.label + " is " + thread1.getState());
            System.out.println(thread2.label + " is " + thread2.getState());
            Thread.sleep(1000L);
        }
    }
}
